/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.epsi.blokus.state;

import de.matthiasmann.twl.Label;
import org.epsi.blokus.Hex;
import org.epsi.blokus.TWL_Slick_Binding.BasicTWLGameState;
import org.epsi.blokus.entity.Loader;
import org.epsi.blokus.tools.I18n;
import org.epsi.blokus.tools.IConstantes;
import org.epsi.blokus.tools.Log;
import org.epsi.blokus.tools.PositionnementUtil;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author julien.lafont
 */
public class AttenteState extends BasicTWLGameState implements IConstantes{

    private GameContainer container;
    private StateBasedGame game;

    private Loader loader;
    
    @Override
    public int getID() {
        return ID_STATE_ATTENTE;
    }

    public void init(GameContainer container, StateBasedGame game) throws SlickException {

        Log.out("AttenteState : init");

        this.container = container;
        this.game = game;

        loader = new Loader();
        loader.init(container, game);
        loader.setPosition(450, 270);
    }

    @Override
    public void enter(GameContainer container, StateBasedGame game) throws SlickException {
        super.enter(container, game);
    }

    

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
        loader.render(container, game, g);
    }

    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        loader.update(container, game, delta);

        // On lance le jeu dés que l'adversaire est prêt
        if (Hex.getInstance().getOpponent().isReady()) game.enterState(ID_STATE_JEU);
    }


    // ---------------------------------- PARTIE GUI -------------------------------- //


    Label txtAttente;
    
    @Override
    protected void createRootPane() {
        super.createRootPane();
        rootPane.setTheme("attentestate");

        txtAttente = new Label(I18n.get("Initialisation de la partie"));
        rootPane.add(txtAttente);

    }

   @Override
    protected void layoutRootPane() {
        super.layoutRootPane();
        rootPane.adjustSize();

        txtAttente.adjustSize();
        txtAttente.setPosition(PositionnementUtil.centrer(txtAttente, rootPane), 220);
    }

}
